package com.sztx.worker_monitor.web.model;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sztx.se.common.util.date.DateUtil;
import com.sztx.se.core.tbschedule.config.TaskRunningInfo;

public class TaskRunInfoModel {
	protected static final Logger logger = LoggerFactory.getLogger(TaskRunInfoModel.class);


	
	/**
	 * 全局唯一标示(当前执行线程的UUID)
	 */
	private String id;

	/**
	 * 调度器名字
	 */
	private String scheduleName;

	/**
	 * 任务名字
	 */
	private String taskName;

	/**
	 * 机器IP地址
	 */
	private String ip;

	/**
	 * 机器名称
	 */
	private String hostName;

	/**
	 * 处理线程数量
	 */
	private int threadNum;

	/**
	 * 开始时间
	 */
	private String registerTime;

	/**
	 * 最后一次心跳通知时间
	 */
	private String lastHeartBeatTime;

	/**
	 * 最后一次取数据时间
	 */
	private String lastFetchDataTime;

	/**
	 * 读取的任务数量
	 */
	private long fetchDataNum;

	/**
	 * 处理成功的任务数量
	 */
	private long dealSucessNum;

	/**
	 * 处理失败的任务数量
	 */
	private long dealFailNum;

	/**
	 * 处理时长(单位:毫秒)
	 */
	private long dealSpendTime;


	public TaskRunInfoModel(String id, String scheduleName, String taskName,
			String ip, String hostName, int threadNum, String registerTime,
			String lastHeartBeatTime, String lastFetchDataTime,
			long fetchDataNum, long dealSucessNum, long dealFailNum,
			long dealSpendTime) {
		super();
		this.id = id;
		this.scheduleName = scheduleName;
		this.taskName = taskName;
		this.ip = ip;
		this.hostName = hostName;
		this.threadNum = threadNum;
		this.registerTime = registerTime;
		this.lastHeartBeatTime = lastHeartBeatTime;
		this.lastFetchDataTime = lastFetchDataTime;
		this.fetchDataNum = fetchDataNum;
		this.dealSucessNum = dealSucessNum;
		this.dealFailNum = dealFailNum;
		this.dealSpendTime = dealSpendTime;
	}

	public TaskRunInfoModel() {
		super();
	}
	
	public TaskRunInfoModel(TaskRunningInfo taskRunningInfo) {
		super();
		if(taskRunningInfo == null) return;
		this.id = taskRunningInfo.getId() +"";
		this.scheduleName = taskRunningInfo.getScheduleName();
		this.taskName = taskRunningInfo.getTaskName();
		this.ip = taskRunningInfo.getIp();
		this.hostName = taskRunningInfo.getHostName();
		this.threadNum = taskRunningInfo.getThreadNum();
		try{
			this.registerTime = DateUtil.formatDate(
					taskRunningInfo.getRegisterTime(), 
					DateUtil.LONG_DATE_FORMAT_STR);
		}catch(Exception e){
			logger.warn(e.toString());
			this.registerTime = "";
		}
		
		try{
			this.lastHeartBeatTime = DateUtil.formatDate(
					taskRunningInfo.getLastHeartBeatTime(), 
					DateUtil.LONG_DATE_FORMAT_STR);
		}catch(Exception e){
			logger.warn(e.toString());
			this.lastHeartBeatTime = "";
		}
		
		try{
			this.lastFetchDataTime = DateUtil.formatDate(
					taskRunningInfo.getLastFetchDataTime(), 
					DateUtil.LONG_DATE_FORMAT_STR);
		}catch(Exception e){
			logger.warn(e.toString());
			this.lastFetchDataTime = "";
		}
		

		this.fetchDataNum = taskRunningInfo.getFetchDataNum();
		this.dealSucessNum = taskRunningInfo.getDealSucessNum();
		this.dealFailNum = taskRunningInfo.getDealFailNum();
		this.dealSpendTime = taskRunningInfo.getDealSpendTime();
		
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getScheduleName() {
		return scheduleName;
	}

	public void setScheduleName(String scheduleName) {
		this.scheduleName = scheduleName;
	}

	public String getTaskName() {
		return taskName;
	}

	public void setTaskName(String taskName) {
		this.taskName = taskName;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getHostName() {
		return hostName;
	}

	public void setHostName(String hostName) {
		this.hostName = hostName;
	}

	public int getThreadNum() {
		return threadNum;
	}

	public void setThreadNum(int threadNum) {
		this.threadNum = threadNum;
	}

	public String getRegisterTime() {
		return registerTime;
	}

	public void setRegisterTime(String registerTime) {
		this.registerTime = registerTime;
	}

	public String getLastHeartBeatTime() {
		return lastHeartBeatTime;
	}

	public void setLastHeartBeatTime(String lastHeartBeatTime) {
		this.lastHeartBeatTime = lastHeartBeatTime;
	}

	public String getLastFetchDataTime() {
		return lastFetchDataTime;
	}

	public void setLastFetchDataTime(String lastFetchDataTime) {
		this.lastFetchDataTime = lastFetchDataTime;
	}

	public long getFetchDataNum() {
		return fetchDataNum;
	}

	public void setFetchDataNum(long fetchDataNum) {
		this.fetchDataNum = fetchDataNum;
	}

	public long getDealSucessNum() {
		return dealSucessNum;
	}

	public void setDealSucessNum(long dealSucessNum) {
		this.dealSucessNum = dealSucessNum;
	}

	public long getDealFailNum() {
		return dealFailNum;
	}

	public void setDealFailNum(long dealFailNum) {
		this.dealFailNum = dealFailNum;
	}

	public long getDealSpendTime() {
		return dealSpendTime;
	}

	public void setDealSpendTime(long dealSpendTime) {
		this.dealSpendTime = dealSpendTime;
	}
	
	
	

}
